# RUN: llc -ppc-asm-full-reg-names -mtriple=powerpc-ibm-aix-xcoff \
# RUN:   -run-pass=ppc-ctrloops %s -o - -verify-machineinstrs | FileCheck %s 

---
name:            test_success1
# CHECK: test_success1

tracksRegLiveness: true
body:             |
  bb.0.entry:

    %0:gprc = LI 2048
    ; CHECK: MTCTRloop
    ; CHECK: BDNZ
    ; CHECK-NOT: ADDI
    ; CHECK-NOT: CMPLWI
    ; CHECK-NOT: BC
    MTCTRloop killed %0:gprc, implicit-def dead $ctr

  bb.1:

    %1:crbitrc = DecreaseCTRloop 1, implicit-def dead $ctr, implicit $ctr
    BC killed %1:crbitrc, %bb.1
    B %bb.2

  bb.2:

    BLR implicit $lr, implicit $rm
...
---
name:            test_fail_clobber
# CHECK: test_fail_clobber
tracksRegLiveness: true
body:             |
  bb.0.entry:

    %0:gprc = LI 2048
    ; CHECK-NOT: MTCTRloop
    ; CHECK-NOT: BDNZ
    ; CHECK: ADDI
    ; CHECK: CMPLWI
    ; CHECK: BC
    MTCTRloop killed %0:gprc, implicit-def dead $ctr

  bb.1:

    INLINEASM &"", 1 /* sideeffect attdialect */, 12 /* clobber */, implicit-def early-clobber $ctr
    %1:crbitrc = DecreaseCTRloop 1, implicit-def dead $ctr, implicit $ctr
    BC killed %1:crbitrc, %bb.1
    B %bb.2

  bb.2:

    BLR implicit $lr, implicit $rm
...
---
name:            test_fail_use_in_loop
# CHECK: test_fail_use_in_loop
tracksRegLiveness: true
body:             |
  bb.0.entry:

    %0:gprc = LI 2048
    ; CHECK-NOT: MTCTRloop
    ; CHECK-NOT: BDNZ
    ; CHECK: ADDI
    ; CHECK: CMPLWI
    ; CHECK: BC
    MTCTRloop killed %0:gprc, implicit-def dead $ctr

  bb.1:

    %1:gprc = MFCTR implicit $ctr
    %2:crbitrc = DecreaseCTRloop 1, implicit-def dead $ctr, implicit $ctr
    BC killed %2:crbitrc, %bb.1
    B %bb.2

  bb.2:

    BLR implicit $lr, implicit $rm
...
---
name:            test_fail_call_in_preheader_after_mtctr
# CHECK: test_fail_call_in_preheader_after_mtctr
tracksRegLiveness: true
body:             |
  bb.0.entry:

    %0:gprc = LI 2048
    ; CHECK-NOT: MTCTR
    ; CHECK-NOT: BDNZ
    ; CHECK: ADDI
    ; CHECK: CMPLWI
    ; CHECK: BC
    MTCTRloop killed %0:gprc, implicit-def dead $ctr
    BL @test_fail_use_in_loop, csr_aix32, implicit-def dead $lr, implicit $rm

  bb.1:

    %1:crbitrc = DecreaseCTRloop 1, implicit-def dead $ctr, implicit $ctr
    BC killed %1:crbitrc, %bb.1
    B %bb.2

  bb.2:

    BLR implicit $lr, implicit $rm
...
---
name:            test_succ_call_in_preheader_before_mtctr
# CHECK: test_succ_call_in_preheader_before_mtctr
tracksRegLiveness: true
body:             |
  bb.0.entry:

    %0:gprc = LI 2048
    BL @test_fail_use_in_loop, csr_aix32, implicit-def dead $lr, implicit $rm
    ; CHECK: MTCTR
    ; CHECK: BDNZ
    ; CHECK-NOT: ADDI
    ; CHECK-NOT: CMPLWI
    ; CHECK-NOT: BC
    MTCTRloop killed %0:gprc, implicit-def dead $ctr

  bb.1:

    %1:crbitrc = DecreaseCTRloop 1, implicit-def dead $ctr, implicit $ctr
    BC killed %1:crbitrc, %bb.1
    B %bb.2

  bb.2:

    BLR implicit $lr, implicit $rm
...
---
name:            test_fail_call_in_loop
# CHECK: test_fail_call_in_loop
tracksRegLiveness: true
body:             |
  bb.0.entry:

    %0:gprc = LI 2048
    ; CHECK-NOT: MTCTR
    ; CHECK-NOT: BDNZ
    ; CHECK: ADDI
    ; CHECK: CMPLWI
    ; CHECK: BC
    MTCTRloop killed %0:gprc, implicit-def dead $ctr

  bb.1:

    BL @test_fail_use_in_loop, csr_aix32, implicit-def dead $lr, implicit $rm
    %1:crbitrc = DecreaseCTRloop 1, implicit-def dead $ctr, implicit $ctr
    BC killed %1:crbitrc, %bb.1
    B %bb.2

  bb.2:

    BLR implicit $lr, implicit $rm
...
---
name:            test_fail_indirect_call_in_loop
# CHECK: test_fail_indirect_call_in_loop
tracksRegLiveness: true
body:             |
  bb.0.entry:
   liveins: $r3, $r4

    %0:gprc = LI 2048
    ; CHECK-NOT: MTCTR
    ; CHECK-NOT: BDNZ
    ; CHECK: ADDI
    ; CHECK: CMPLWI
    ; CHECK: BC
    renamable %1:crrc = CMPLW killed renamable $r3, killed renamable $r4
    renamable %2:crbitrc = COPY %1.sub_gt
    MTLR %0:gprc, implicit-def $lr
    MTCTRloop %0:gprc, implicit-def dead $ctr

  bb.1:

    BCLRL renamable %2, implicit $lr, implicit $rm
    %3:crbitrc = DecreaseCTRloop 1, implicit-def dead $ctr, implicit $ctr
    BC killed %3:crbitrc, %bb.1
    B %bb.2

  bb.2:

    BLR implicit $lr, implicit $rm
...
---
name:            test_fail_livein_preheader
# CHECK: test_fail_livein_preheader
tracksRegLiveness: true
body:             |
  bb.0.entry:
    liveins: $ctr

    %0:gprc = LI 2048
    ; CHECK-NOT: MTCTRloop
    ; CHECK-NOT: BDNZ
    ; CHECK: ADDI
    ; CHECK: CMPLWI
    ; CHECK: BC
    MTCTRloop killed %0:gprc, implicit-def dead $ctr

  bb.1:

    %1:crbitrc = DecreaseCTRloop 1, implicit-def dead $ctr, implicit $ctr
    BC killed %1:crbitrc, %bb.1
    B %bb.2

  bb.2:

    BLR implicit $lr, implicit $rm
...
---
name:            test_fail_def_preheader
# CHECK: test_fail_def_preheader
tracksRegLiveness: true
body:             |
  bb.0.entry:

    INLINEASM &"", 1 /* sideeffect attdialect */, 12 /* clobber */, implicit-def early-clobber $ctr
    %0:gprc = LI 2048
    ; CHECK-NOT: MTCTRloop
    ; CHECK-NOT: BDNZ
    ; CHECK: ADDI
    ; CHECK: CMPLWI
    ; CHECK: BC
    MTCTRloop killed %0:gprc, implicit-def dead $ctr

  bb.1:

    %1:crbitrc = DecreaseCTRloop 1, implicit-def dead $ctr, implicit $ctr
    BC killed %1:crbitrc, %bb.1
    B %bb.2

  bb.2:

    BLR implicit $lr, implicit $rm
...
---
name:            test_success_only_use_preheader
# CHECK: test_success_only_use_preheader
tracksRegLiveness: true
body:             |
  bb.0.entry:

    %0:gprc = MFCTR implicit $ctr
    %1:gprc = LI 2048
    ; CHECK: MTCTRloop
    ; CHECK: BDNZ
    ; CHECK-NOT: ADDI
    ; CHECK-NOT: CMPLWI
    ; CHECK-NOT: BC
    MTCTRloop killed %1:gprc, implicit-def dead $ctr

  bb.1:

    %2:crbitrc = DecreaseCTRloop 1, implicit-def dead $ctr, implicit $ctr
    BC killed %2:crbitrc, %bb.1
    B %bb.2

  bb.2:

    BLR implicit $lr, implicit $rm
...
---
name:            test_fail_use_after_mtctr
# CHECK: test_fail_use_after_mtctr
tracksRegLiveness: true
body:             |
  bb.0.entry:

    %0:gprc = LI 2048
    ; CHECK-NOT: MTCTRloop
    ; CHECK-NOT: BDNZ
    ; CHECK: ADDI
    ; CHECK: CMPLWI
    ; CHECK: BC
    MTCTRloop killed %0:gprc, implicit-def dead $ctr
    %1:gprc = MFCTR implicit $ctr

  bb.1:

    %2:crbitrc = DecreaseCTRloop 1, implicit-def dead $ctr, implicit $ctr
    BC killed %2:crbitrc, %bb.1
    B %bb.2

  bb.2:

    BLR implicit $lr, implicit $rm
...
---
name:            test_fail_def_after_mtctr
# CHECK: test_fail_def_after_mtctr
tracksRegLiveness: true
body:             |
  bb.0.entry:

    %0:gprc = LI 2048
    ; CHECK-NOT: MTCTRloop
    ; CHECK-NOT: BDNZ
    ; CHECK: ADDI
    ; CHECK: CMPLWI
    ; CHECK: BC
    MTCTRloop killed %0:gprc, implicit-def dead $ctr
    INLINEASM &"", 1 /* sideeffect attdialect */, 12 /* clobber */, implicit-def early-clobber $ctr

  bb.1:

    %2:crbitrc = DecreaseCTRloop 1, implicit-def dead $ctr, implicit $ctr
    BC killed %2:crbitrc, %bb.1
    B %bb.2

  bb.2:

    BLR implicit $lr, implicit $rm
...
---
name:            test_success_def_after_loop
# CHECK: test_success_def_after_loop
tracksRegLiveness: true
body:             |
  bb.0.entry:

    %0:gprc = LI 2048
    ; CHECK: MTCTRloop
    ; CHECK: BDNZ
    ; CHECK-NOT: ADDI
    ; CHECK-NOT: CMPLWI
    ; CHECK-NOT: BC
    MTCTRloop killed %0:gprc, implicit-def dead $ctr

  bb.1:

    %2:crbitrc = DecreaseCTRloop 1, implicit-def dead $ctr, implicit $ctr
    BC killed %2:crbitrc, %bb.1
    B %bb.2

  bb.2:
    INLINEASM &"", 1 /* sideeffect attdialect */, 12 /* clobber */, implicit-def early-clobber $ctr

    BLR implicit $lr, implicit $rm
...
